package com.platform.dto;

import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.platform.comm.validation.groups.Insert;
import com.platform.enums.ConfValueMode;
import com.platform.utils.Pair;
import com.platform.comm.dto.AbstractQo;
import com.platform.comm.enums.YnEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * Description: 参数设置-DTO
 *
 * @author libin Created on 2019/7/18
 **/
@EqualsAndHashCode(callSuper = true)
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ConfQo extends AbstractQo {

    private static final long serialVersionUID = 2595845938749080923L;
    /**
     * 类别ID
     */
    @NotEmpty(message = "所属类别不能为空", groups = Insert.class)
    private String typeId;

    /**
     * 设置编码
     */
    @NotEmpty(message = "设置编码不能为空", groups = Insert.class)
    @Size(max = 100, message = "设置编码长度不能超过100个字符")
    private String confCode;

    /**
     * 完整编码
     */
    @Size(max = 1024, message = "完整编码长度不能超过1024个字符")
    private String routeCode;

    /**
     * 名称
     */
    @NotEmpty(message = "名称不能为空", groups = Insert.class)
    @Size(max = 256, message = "名称长度不能超过256个字符")
    private String confName;

    /**
     * 值
     */
    private JSONObject confValue;


    /**
     * 取值模式: 1: 字符串, 2：内部单选，3：内部多选，4：图片
     */
    @Pattern(regexp = "[1-4]", message = "取值模式不合法")
    private ConfValueMode valueMode;

    /**
     * 取值范围
     */
    private JsonNode valueMapping;

    /**
     * 取值范围
     */
    private List<Pair<String, Object>> valueMappingList;

    /**
     * 字典项
     */
    @Size(max = 64, message = "字典项长度不能超过64个字符")
    private String dictName;

    /**
     * 描述
     */
    @Size(max = 1024, message = "描述长度不能超过1024个字符")
    private String desc;

    /**
     * 排序编号
     */
    private Integer sortNum;

    /**
     * 状态 0：否，1：是
     */
    @Pattern(regexp = "[01YN]", message = "信息状态不合法")
    private YnEnum delFlag;

    /**
     * 字典 KEY类型 字符串：string 数值：number
     */
    private String keyType;

    @Override
    public void init() {
        this.setDelFlag(YnEnum.N);
        if (this.getSortNum() == null) {
            this.setSortNum(0);
        }
    }
}
